﻿using MiniFox.Data.Mapping;
using MiniFox.Infrastructure;
using MiniFox.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Reflection;

namespace MiniFox.Data
{
    /// <summary>
    /// 结果集
    /// </summary>
    public class ResultSet : ResultSet<IDictionary<string, object>>
    {
        /// <summary>
        /// 
        /// </summary>
        public ResultSet()
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="entity"></param>
        /// <param name="model"></param>
        /// <param name="colMapping"></param>
        protected override void MapEntityToModel<TModel>(IDictionary<string, object> entity, TModel model, IColumnMapping colMapping)
        {
            var modelType = typeof(TModel);
            if (!entity.ContainsKey(colMapping.SourceColumn)) return;
            object val = entity[colMapping.SourceColumn];
            var property = modelType.GetProperty(colMapping.DataSetColumn);
            property.SetValue(model, val);
        }
        /// <summary>
        /// 创建视图表结果对象，含行列集
        /// </summary>
        /// <returns></returns>
        public override ResultObject<ViewTable> GetTableResultObject()
        {
            throw new NotSupportedException();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataItem"></param>
        /// <param name="row"></param>
        /// <param name="colMapping"></param>
        protected override void MapDataItemToViewRow(IDictionary<string, object> dataItem, ViewRow row, IColumnMapping colMapping)
        {
            if (!dataItem.ContainsKey(colMapping.SourceColumn)) return;
            row[colMapping.DataSetColumn] = dataItem[colMapping.SourceColumn];
        }
    }

}
